//
//  OrderViewController.m
//  YiBaoStore
//
//  Created by 吕清毅 on 2018/10/6.
//  Copyright © 2018年 小河. All rights reserved.
//

#import "OrderViewController.h"
#import "AllOrderViewController.h"
#import "FreezeViewController.h"
#import "NoPayViewController.h"
#import "PayOrderViewController.h"
#import "NoDeliverViewController.h"

@interface OrderViewController ()

@end

@implementation OrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = TotalWhite;
    [self setNavi];
    //创建四个切换按钮
    [self createSegment];
    //进来的界面是第几个界面
    [self selectToSelectedIndex:self.buttionIdex];
    if (self.amount.length > 0) { //是否需要提示充值
       //  [self setTipView];
    }
}

#pragma mark -- 货款不足
- (void)setTipView
{
    UIView *backView = [UIView new];
    if (@available(iOS 11.0, *)) {
        backView.frame = CGRectMake(0, SCREENHEIGHT-116-BottomHeight_xs, SCREENWIDTH, 116);
    } else {
        // Fallback on earlier versions
        backView.frame = CGRectMake(0, SCREENHEIGHT-116-BottomHeight, SCREENWIDTH, 116);
    }
    backView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:backView];
    UIColor *colorOne = HexWithAlpha(0xffffff, 0);
    UIColor *colorTwo = HexWithAlpha(0xffffff, 1.0);
    NSArray *colors = [NSArray arrayWithObjects:(id)colorOne.CGColor, colorTwo.CGColor, nil];
    CAGradientLayer*gradient = [CAGradientLayer layer];
    backView.layer.masksToBounds = YES;//设置开始和结束位置(设置渐变的方向)
    gradient.startPoint = CGPointMake(0, 0);
    gradient.endPoint = CGPointMake(0, 1);
    gradient.colors = colors;
    gradient.frame = CGRectMake(0, 0, backView.width, backView.height);
    [backView.layer insertSublayer:gradient atIndex:0];
    
    UIImageView *backIV = [UIImageView new];
    backIV.frame = CGRectMake(10, 16, SCREENWIDTH-20, 80);
    backIV.image = [UIImage imageNamed:@"backTipView"];
    backIV.userInteractionEnabled = YES;
    [backView addSubview:backIV];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(backIV.width-96, 19, 82, 42);
    [backBtn setBackgroundImage:[UIImage imageNamed:@"rechargeBtn"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(ChargeBtn:) forControlEvents:UIControlEventTouchUpInside];
    [backIV addSubview:backBtn];
    
    UILabel *titleLab = [UILabel new];
    titleLab.frame = CGRectMake(127, 19, 72, 18);
    titleLab.textColor = titleColor;
    titleLab.font = FontWithSize(18);
    titleLab.text = @"货款不足";
    [backIV addSubview:titleLab];
    
    UILabel *desLab = [UILabel new];
    desLab.frame = CGRectMake(109, titleLab.bottom+11, 140, 12);
    desLab.textColor = titleColor;
     desLab.font = FontMediumWithSize(12);
    desLab.text = [NSString stringWithFormat:@"充值¥%@完成发货",self.amount];
    [backIV addSubview:desLab];
}

- (void)createSegment
{
    self.titleArr = self.isFronze==YES?@[@"全部",@"冻结",@"待取货",@"待发货",@"待收货"]:@[@"全部",@"待取货",@"待发货",@"待收货"];
    AllOrderViewController *allVC = [AllOrderViewController new];
    FreezeViewController *freezeVC = [FreezeViewController new];
    NoPayViewController *noPayVC = [NoPayViewController new];
    NoDeliverViewController *noDeliVC = [NoDeliverViewController new];
    PayOrderViewController *payVC = [PayOrderViewController new];
    self.controllerArr = self.isFronze==YES?@[allVC,freezeVC,noPayVC,noDeliVC,payVC]:@[allVC,noPayVC,noDeliVC,payVC];
}

- (void)setNavi
{
    UIView *navi = [UIView new];
    if (@available(iOS 11.0, *)) {
        navi.frame = CGRectMake(0, 0, SCREENWIDTH, TopBarHeight_xs);
    } else {
        // Fallback on earlier versions
        navi.frame = CGRectMake(0, 0, SCREENWIDTH, TopBarHeight);
    }
    navi.tag = 20;
    navi.backgroundColor = TotalWhite;
    [self.view addSubview:navi];
    
    UIImageView *leftIV = [UIImageView new];
    leftIV.frame = CGRectMake(15, navi.height-15-18, 18, 14);
    leftIV.image = [UIImage imageNamed:@"back"];
    [navi addSubview:leftIV];
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(8, navi.height-40, 32, 28);
    leftBtn.backgroundColor = ClearColor;
    [leftBtn addTarget:self action:@selector(leftBtnBackClick:) forControlEvents:UIControlEventTouchUpInside];
    [navi addSubview:leftBtn];
    
    UILabel *titleLab = [UILabel new];
    CGFloat left = 30+18;
    titleLab.frame = CGRectMake(left, navi.height-13-18, SCREENWIDTH-96, 18);
    titleLab.textColor = titleColor;
    titleLab.tag = 30;
    titleLab.font = FontSemiboldSize(18);
    titleLab.attributedText = [TTKUtil getAtttributeStringWithLineSpace:0 kern:-0.9 and:@"订单中心"];
    titleLab.textAlignment = NSTextAlignmentCenter;
    [navi addSubview:titleLab];
    
    UIView *line = [UIView new];
    if (@available(iOS 11.0, *)) {
        line.frame = CGRectMake(0, TopBarHeight_xs-1, SCREENWIDTH, 1);
    } else {
        // Fallback on earlier versions
        line.frame = CGRectMake(0, TopBarHeight-1, SCREENWIDTH, 1);
    }
    line.backgroundColor = UIColorFromHex(0xF1F1F1);
    [navi addSubview:line];
    
    /*  订单搜索先移除
    UIImageView *rightIV = [UIImageView new];
    rightIV.frame = CGRectMake(navi.width-33, navi.height-15-18, 18, 18);
    rightIV.image = [UIImage imageNamed:@"search"];
    [navi addSubview:rightIV];
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(navi.width-40, navi.height-40, 32, 32);
    rightBtn.backgroundColor = ClearColor;
    [rightBtn addTarget:self action:@selector(rightBtnBackClick:) forControlEvents:UIControlEventTouchUpInside];
    [navi addSubview:rightBtn];
     */
}

- (void)leftBtnBackClick:(UIButton *)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -- 充值
- (void)ChargeBtn:(UIButton*)btn
{
    
    [self.navigationController pushViewController:[RechargeViewController new] animated:YES];
}

- (void)rightBtnBackClick:(UIButton *)btn
{
    NSLog(@"search");
}
@end
